package com.zj.app;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import com.zj.pojo.User;
@Component
@Aspect
public class MyAdvice {
    //定义切入点  将要切入的方法
    /*@Pointcut("execution(public * com.zj.Dao.UserDao.selectById())")*/
   /* @Pointcut("execution(* com.zj.Dao.UserDao.selectById())")*/
    /*@Pointcut("execution(public * com.zj.Dao.UserDao.selectById(*))")*/
   /* @Pointcut("execution(public * com.zj.Dao.UserDao.selectById(..))")*/
    /*@Pointcut("execution(public * *..s*(..))") s开头方法*/
    @Pointcut("execution(public * *..*d(..))")
    private void pt(){

    }

    //被切入的方法
   /* @Before("pt()")
    @After("pt()")
    @AfterReturning  有异常 不执行
    @AfterThrowing  有异常 才执行*/
    @Around("pt()")
    public Object method(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("被切入的方法...");
        //原始操作的调用
        Object obj = pjp.proceed();//环绕通知
        System.out.println(System.currentTimeMillis());
        return obj;
    }
    @AfterReturning(value = "pt()",returning = "ret")
    public void methods(JoinPoint jp,Object ret) throws Throwable {
        System.out.println("被切入的方法...");
        System.out.println(ret);
    }
}
